package com.htandroid.htandroid.webservice;

import android.util.Xml;

import com.htandroid.htandroid.entity.MrqgdDjList;
import com.htandroid.htandroid.entity.SplcLinesChar;

import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class abXMLMrqgdlist {

    /**
     * 解析评论xml信息
     *
     * @param content
     * @return
     */
    public static ArrayList<MrqgdDjList> paraseCommentInfors(String content) {
        List<String> list = new ArrayList<String>();
        content = content.replace("MrqgdDjList=anyType", "#=#");
        String[] strs = content.split("#=");
        for (int i = 0; i < strs.length; i++) {
            if (strs[i].contains("#")) {
                list.add(strs[i].replace("#", "").trim().replace(" ", ""));
            }
        }
        ArrayList<MrqgdDjList> mrqgdlist = new ArrayList<MrqgdDjList>();
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                list.set(i, list.get(i).replace(";};};}", "\"}"));
            }
            list.set(i, list.get(i).replace(";};", "\"}").replace("=", "\":\"").replace(";", "\",\"").replace("{bchecked", "{\"bchecked"));
            try {
                MrqgdDjList info = new MrqgdDjList();
                JSONObject dataJson = new JSONObject(list.get(i));
                info.setIds(string2null(dataJson.getString("ids")));
                info.setCvouchid(string2null(dataJson.getString("cvouchid")));
                info.setcDepcode(string2null(dataJson.getString("cDepcode")));
                info.setCdepname(string2null(dataJson.getString("cdepname")));
                info.setcInvcCode(string2null(dataJson.getString("cInvcCode")));
                info.setcInvcName(string2null(dataJson.getString("cInvcName")));
                info.setcInvcode(string2null(dataJson.getString("cInvcode")));
                info.setcInvname(string2null(dataJson.getString("cInvname")));
                info.setcInvstd(string2null(dataJson.getString("cInvstd")));
                info.setcInvm_unit(string2null(dataJson.getString("cInvm_unit")));
                info.setiQuantity(string2null(dataJson.getString("iQuantity")));
                info.setIprice(string2null(dataJson.getString("iprice")));
                info.setIamount(string2null(dataJson.getString("iamount")));
                info.setCvencode(string2null(dataJson.getString("cvencode")));
                info.setCvenname(string2null(dataJson.getString("cvenname")));
                info.setCvenemail(string2null(dataJson.getString("cvenemail")));
                info.setCventel(string2null(dataJson.getString("cventel")));
                info.setdDhDate(string2null(dataJson.getString("dDhDate")));
                info.setBinvtype(string2null(dataJson.getString("binvtype")));
                info.setDjtype(string2null(dataJson.getString("djtype")));
                info.setDjcvencode(string2null(dataJson.getString("djcvencode")));
                info.setDjprice(string2null(dataJson.getString("djprice")));
                info.setCmemo(string2null(dataJson.getString("cmemo")));
                info.setCanupdjxy(string2null(dataJson.getString("canupdjxy")));
                info.setdDate(string2null(dataJson.getString("dDate")));
                info.setBchecked(string2null(dataJson.getString("bchecked")));
                mrqgdlist.add(info);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return mrqgdlist;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }

}  
